package com.example.controller;

import com.example.domain.Patient;
import com.example.domain.Record;
import com.example.service.PatientService;
import com.example.service.RecordService;
import com.example.utils.AjaxResult;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

import static com.example.utils.AjaxResult.*;
import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("/root")

public class PatientController {
    @Autowired
    private PatientService patientService;

    @RequestMapping("/patient")
    public AjaxResult Patient(@RequestParam(defaultValue = "1", value = "page") Integer pageNum,
                              @RequestParam(defaultValue = "10", value = "limit") Integer pageSize,
                              @RequestParam(defaultValue = "" , value = "patient") String usr
                              ){

        HashMap<String, Object> map = new HashMap<>();
        PageHelper.startPage(pageNum,pageSize);
        if (usr == null || usr.equals("")) {
            map.put("usr","");
            List<Patient> patient = patientService.listAll(2);
            System.out.println(patient.toString());
            PageInfo<Patient> page = new PageInfo<>(patient);
            return successData(page.getTotal(), patient);
        }
        map.put("usr",usr);
        List<Patient> patient = patientService.listAll(2);
        PageInfo<Patient> page = new PageInfo<>(patient);
        return successData(page.getTotal(), patient);
    }
}
